import redis
import hashlib

class UrlFilter:
    def __init__(self):
        self.redis_config = {
            'host':'localhost',
            'port':6379
        }
        self.pool = redis.ConnectionPool(host='localhost',port=6379)
        self.redis = redis.StrictRedis(connection_pool=self.pool)
        self.key = 'product_id'

    def id_md5(self,data):
        m = hashlib.md5()
        m.update(data.encode('utf-8'))
        md5 = m.hexdigest()
        return md5

    def id_check(self,data):
        md5 = self.id_md5(data)
        id_exit = self.redis.sismember(self.key,md5)
        return id_exit


    def id_add(self,data):
        md5 = self.id_md5(data)
        self.redis.sadd(self.key, md5)

